//
//  YZMyStocksHeaderView.m
//  YZMicroStock
//
//  Created by wangminhong on 16/3/30.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMyStocksHeaderView.h"
#import "YZMAppStyle.h"
#import <Masonry/Masonry.h>

@interface YZMyStocksHeaderView()

@property (nonatomic, strong) UILabel *nameLB;
@property (nonatomic, strong) UIButton *priceBT;
@property (nonatomic, strong) UIImageView *priceIV;
@property (nonatomic, strong) UIButton *rangeBT;
@property (nonatomic, strong) UIImageView *rangeIV;

@end

@implementation YZMyStocksHeaderView

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithReuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.contentView.backgroundColor = [YZMAppStyle colorForMain];
        [self createObjects];
    }
    
    return self;
}

#pragma mark -- event

- (void)priceButtonPressed:(UIButton *)sender{
    
}

- (void)rangeButtonPressed:(UIButton *)sender{
    
    
}

- (void)setStyle:(YZMStockHeaderType)style{
    
    switch (style) {
        case YZMStockHeaderTypeForShow: {
            [self.priceBT setTitle:@"当前价" forState:UIControlStateNormal];
            [self.rangeBT setTitle:@"涨跌幅" forState:UIControlStateNormal];
            break;
        }
        case YZMStockHeaderTypeForEdit: {
            [self.priceBT setTitle:@"置顶" forState:UIControlStateNormal];
            [self.rangeBT setTitle:@"拖动" forState:UIControlStateNormal];
            break;
        }
    }
}

#pragma mark -- ui

- (void)createObjects{
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [YZMAppStyle appBackgroundColor];
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.top.equalTo(self);
        make.height.mas_equalTo(14);
    }];
    
    self.nameLB = [YZMAppStyle labelWithMediumWhite];
    self.nameLB.text = @"股票名称";
    [self addSubview:self.nameLB];
    [self.nameLB mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self).offset(15);
        make.top.equalTo(bgView.mas_bottom).offset(8);
        make.bottom.equalTo(self).offset(-8);
    }];
    
    self.priceBT = [UIButton new];
    self.priceBT.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.priceBT setTitle:@"当前价" forState:UIControlStateNormal];
    [self.priceBT setTitleColor:[YZMAppStyle colorForWhite] forState:UIControlStateNormal];
    [self.priceBT.titleLabel setFont:[YZMAppStyle mediumSizeFont]];
    
    [self.priceBT addTarget:self action:@selector(priceButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.priceBT];
    [self.priceBT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_centerX).offset(40);
        make.centerY.equalTo(self.nameLB);
    }];
    
    self.rangeBT = [UIButton new];
    self.rangeBT.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.rangeBT setTitle:@"  涨跌幅" forState:UIControlStateNormal];
    [self.rangeBT setTitleColor:[YZMAppStyle colorForWhite] forState:UIControlStateNormal];
    [self.rangeBT.titleLabel setFont:[YZMAppStyle mediumSizeFont]];
    [self addSubview:self.rangeBT];
    [self.rangeBT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-15);
        make.centerY.equalTo(self.nameLB);
    }];
    
    UIView *lineView = [YZMAppStyle splitLine];
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.bottom.equalTo(self).offset(10);
        make.right.equalTo(self).offset(-10);
        make.bottom.equalTo(self);
    }];
}

@end
